<?php

/**
 * Last 12 months
 * @package ModuleStatistiques
 * @version 1.0b
 * @return JSON
 */

session_start();

// Configuration file
include '../../configuration.php';
// Functions
include '../../inc/functions.php';

// Checking if user is logged in
if (!CheckSession()):
	exit();
endif;

// Database connexion string
$db_str = "mysql:dbname=".$configuration['db'].";host=".$configuration['host'];

// Collecting numeric stats
try {
	
	// Connecting to database
	$db = new PDO($db_str, $configuration['user'], $configuration['pass']);
	
	// Query
	$sql = 'SELECT studentactivity.name AS "Activité" FROM studentactivity;';
	
	// Executing query
	$query = $db->prepare($sql);
	$query->execute();
	
	// Fetching data
	$result = $query->fetchAll(PDO::FETCH_ASSOC);
	
	// Rendering data
	$categories = Array();
	
	for ($i = 11; $i >= 0; --$i)
		array_push($categories, date('M-y', mktime(0, 0, 0, date('m')-$i, date('d'), date('y'))));
		
	echo json_encode($categories);
	
} catch (Exception $e) {
	echo $e->getMessage();
}

?>